package com.example.leetdemo.plan1;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Sword046 {

    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        Queue<TreeNode> queue = new ArrayDeque<>();
        queue.offer(root);
        while (queue.size() > 0) {
            int t = -1;
            Queue<TreeNode> queue1 = new ArrayDeque<>();
            while (queue.size() > 0) {
                TreeNode y = queue.poll();
                t = y.val;
                if (y.left != null) {
                    queue1.offer(y.left);
                }
                if (y.right != null) {
                    queue1.offer(y.right);
                }
            }
            list.add(t);
            queue = queue1;
        }
        return list;
    }

}
